package com.zhang.controller;

import com.zhang.pojo.UserBean;
import com.zhang.service.IUserService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private IUserService service;

    @RequestMapping("login")
    public String login(HttpServletRequest req,String username,String pwd){
        UserBean login = service.login(username, pwd);
        if (login == null){
            return "no";
        }
        req.getSession().setAttribute("user",login);
        return login.getGrade();
    }

    @RequestMapping("getUser")
    public UserBean getUser(HttpServletRequest req){
        return (UserBean) req.getSession().getAttribute("user");
    }
}
